/*

	This file constructs promotion data at firm-destination-year level across different support products

*/

cd ${work}4_reg_variables


* GROUPING
local list1 `" "Partner Search and Match Making" "Meeting Facilitation" "Facilitation of Networks and Communities" "'
local list2 `" "Fairs and Exhibitions" "PR Activities and Events" "Conferences, Workshops and Seminars" "'
local list3 `" "Intelligence and Analysis" "Publications (reports, subsid lists etc)" "Market Monitoring" "Customs, Export and Import Information" "'
local list4 `" "Other Commercial Assistance" "Market Entry Assistance" "Trade Policy, incl. Breakdown of Trade Barriers"  "'

use product using input\promotion, clear
duplicates drop 

gen product_num = .
local n=1
while `n'<=4 {
	foreach x of local list`n' {
		replace product_num = `n' if product=="`x'"
	}
	local ++n
}
	replace product_num = `n' if product_num==.

keep product product_num
compress
save temp\promotion_products, replace

* CREATE DATA
use input\promotion, clear

*shape
merge m:1 product using temp\promotion_products, assert(3) keepusing(product_num) nogen	
erase temp\promotion_products.dta
drop product

collapse (max) treated tdcinitiative , by(jurnr_num land year product_num)

foreach v of varlist treated tdcinitiative {
    rename `v' `v'_p
}
reshape wide treated_p tdcinitiative_p , i(jurnr_num land year) j(product_num)

*balance in years
reshape wide *_p* , i(jurnr_num land) j(year)
reshape long

*promotion specifications
egen fd=group(jurnr_num land)
xtset fd year
foreach v of varlist treated_p* tdcinitiative_p* {
	replace `v'=0 if `v'==.
	rename `v' `v'_1
	gen `v'_2 = (`v'_1==1 | l.`v'_1==1)	if year>2002
}

*save
keep jurnr_num land year treated_* tdcinitiative_*
compress
save output\promotion_product_idt, replace